import {
    Entity,
    Column,
    Index,

} from 'typeorm';
import { BaseEntity } from './base.entity';

@Entity({ name: 'articles' }) // 指定表名
export class Article extends BaseEntity {

    @Column({
        name: 'title',
        type: 'varchar',
        length: 100,
        comment: '文章标题',
        nullable: false
    })
    title!: string;

    @Column({
        name: 'content',
        type: 'text',
        comment: '文章内容',
        nullable: false
    })
    content!: string;

    @Column({
        name: 'cover_image',
        type: 'varchar',
        length: 255,
        comment: '封面图URL',
        nullable: true
    })
    coverImage!: string | null;


    @Column({
        name: 'view_count',
        type: 'int',
        comment: '阅读量',
        default: 0,
        nullable: false
    })
    viewCount!: number;

    @Index('idx_user_id') // 创建索引
    @Column({
        name: 'user_id',
        type: 'int',
        comment: '作者ID',
        nullable: false
    })
    userId!: number;

    @Index('idx_category_id') // 创建索引
    @Column({
        name: 'category_id',
        type: 'int',
        comment: '分类ID',
        nullable: true
    })
    categoryId!: number | null;

}